package com.li.drug.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.li.drug.entity.Saleinfo;
import com.li.drug.mapper.SaleinfoMapper;
import com.li.drug.service.SaleinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

/**
 * 销售记录service实现类
 */
@Service
public class SaleinfoServiceImpl extends ServiceImpl<SaleinfoMapper, Saleinfo> implements SaleinfoService {

    @Autowired
    SaleinfoMapper saleinfoMapper;

    /**
     * 分页查询销售记录数据
     * @param pageNum 第几页
     * @param pageSize 每页多少条数据
     * @param param 查询参数 - 药品名称
     * @return
     */
    @Override
    public Page<Saleinfo> selectSaleinfoPage(int pageNum, int pageSize, String param) {
        //构建查询条件
        QueryWrapper<Saleinfo> wrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(param)){
            wrapper.like("dname",param);
        }
        //构建分页查询对象
        Page<Saleinfo> page = new Page<>(pageNum,pageSize);
        return saleinfoMapper.selectPage(page,wrapper);
    }

    @Override
    public int addSaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.insert(saleinfo);
    }

    @Override
    public int editSaleinfo(Saleinfo saleinfo) {
        return saleinfoMapper.updateById(saleinfo);
    }

    @Override
    public Saleinfo getSaleinfoById(Integer id) {
        return saleinfoMapper.selectById(id);
    }

    @Override
    public int delSaleinfoById(Integer id) {
        return saleinfoMapper.deleteById(id);
    }
}
